package com.blu.jsoup;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.blu.job.parselist;

public class HtmlParseUtil  {
	
	public static void parse(String username) throws MalformedURLException, IOException{
		for(int i=1;i<=1000;i++) {
			String url="https://blog.csdn.net/"+username+"/article/list/"+i;
			try {
				Document doc = Jsoup.parse(new URL(url),15000);
				Elements elements = doc.getElementsByClass("article-list").get(0).getElementsByTag("a");
				if(elements.size()==0) {
					i=1001;
				}
				for(Element e : elements) {
					parselist.list.add(e.attr("href"));
				}
			} catch (Exception e) {
				i=1001;
			}
		}
		String url="https://blog.csdn.net/"+username+"/article/list/1";
		try {
			Document doc = Jsoup.parse(new URL(url),20000);
			String read = doc.getElementById("asideProfile").getElementsByClass("text-center").get(3).getElementsByTag("dt").get(0).getElementsByTag("span").get(0).text();
			parselist.read = read;
		} catch (Exception e) {
			parselist.read = null;
		}
		
	}

}
